"use client"
import * as React from 'react'
import Link from 'next/link'
import { Brain, Copy } from 'lucide-react'
import { Button } from '@open-mercato/ui/primitives/button'
import { Tag } from '@open-mercato/ui/primitives/tag'
import { SectionHeader } from '@open-mercato/ui/backend/SectionHeader'
import { flash } from '@open-mercato/ui/backend/FlashMessages'
import { useT, useLocale } from '@open-mercato/shared/lib/i18n/context'
import { formatNumber, type AgentDetailView, type SkillDetailView } from '../../../../components/types'
import { TokenUsageCard } from './workspacePrimitives'
import type { RuntimeTokenUsage } from './workspaceShared'
type ConfigurationTabProps = {
agent: AgentDetailView
runtimeTokens: RuntimeTokenUsage | null
onSkillClick: (skill: SkillDetailView) => void
}
export function ConfigurationTab({ agent, runtimeTokens, onSkillClick }: ConfigurationTabProps) {
const t = useT()
const locale = useLocale()
const defaultValue = t('agent_orchestrator.agentDetail.defaultValue', 'Default')
const copyInstructions = () => {
if (!agent.instructions || typeof navigator === 'undefined' || !navigator.clipboard) return
navigator.clipboard.writeText(agent.instructions).then(
() => flash(t('agent_orchestrator.agentDetail.instructionsCopied', 'Instructions copied to clipboard.'), 'success'),
() => flash(t('agent_orchestrator.agentDetail.copyFailed', 'Could not copy to clipboard.'), 'error'),
)
}
return (
{t('agent_orchestrator.agentDetail.copy', 'Copy')}
{agent.instructions || t('agent_orchestrator.agentDetail.defaultValue')}
{agent.tools.length ? (
{agent.tools.map((tool) => {tool} )}
) : (
{t('agent_orchestrator.agentDetail.noTools')}
)}
{t('agent_orchestrator.agentDetail.fields.provider', 'Provider')}
{agent.defaultProvider ?? defaultValue}
{t('agent_orchestrator.agentDetail.fields.model', 'Model')}
{agent.defaultModel ?? defaultValue}
{t('agent_orchestrator.agentDetail.fields.maxSteps', 'Max steps')}
{agent.loopMaxSteps != null ? String(agent.loopMaxSteps) : defaultValue}
{t('agent_orchestrator.agentDetail.config.runtimeKind', 'Runtime')}
{agent.runtime}
{t('agent_orchestrator.agentDetail.config.resultKind', 'Result kind')}
{agent.resultKind}
{/* The DECLARED type is an authoring fact and sits beside — never
instead of — the runtime result kind; the two may legitimately
disagree. */}
{t('agent_orchestrator.agentDetail.config.agentType', 'Agent type')}
{agent.agentType
? t(`agent_orchestrator.agents.list.agentType.${agent.agentType}`)
: t('agent_orchestrator.agents.list.agentType.undeclared', 'Undeclared')}
{/* `null` = no narrowing declared (the whole catalogue); an EMPTY list =
everything declared fell outside the catalogue and was dropped. The
two must not read the same — one is permissive, the other forbids
every effect. */}
{agent.allowedActions == null ? (
{t('agent_orchestrator.agentDetail.allowedActions.catalogue')}
) : agent.allowedActions.length === 0 ? (
{t('agent_orchestrator.agentDetail.allowedActions.none')}
) : (
{t('agent_orchestrator.agentDetail.allowedActions.narrowed', undefined, {
count: agent.allowedActions.length,
})}
{agent.allowedActions.map((action) => (
{action}
))}
)}
{runtimeTokens ? (
{t('agent_orchestrator.agentDetail.tokens.perRun', 'Per run (avg)')}
{formatNumber(runtimeTokens.inputAvg, locale)} {t('agent_orchestrator.agentDetail.tokens.in', 'in')} · {formatNumber(runtimeTokens.outputAvg, locale)} {t('agent_orchestrator.agentDetail.tokens.out', 'out')}
{t('agent_orchestrator.agentDetail.tokens.recentTotal', 'Recent {count} runs', { count: runtimeTokens.count })}
{formatNumber(runtimeTokens.inputTotal, locale)} {t('agent_orchestrator.agentDetail.tokens.in', 'in')} · {formatNumber(runtimeTokens.outputTotal, locale)} {t('agent_orchestrator.agentDetail.tokens.out', 'out')}
) : (
{t('agent_orchestrator.agentDetail.tokens.none', 'No runs have reported token usage yet.')}
)}
{agent.skillDetails.length ? (
{agent.skillDetails.map((skill) => (
onSkillClick(skill)}
className="h-auto w-full items-start justify-start gap-3 rounded-lg border border-border bg-card p-3 text-left font-normal hover:bg-accent/30"
aria-label={t('agent_orchestrator.agentDetail.viewSkill', undefined, { skill: skill.label })}
>
{skill.description ?
{skill.description}
: null}
))}
) : (
{t('agent_orchestrator.agentDetail.noSkills')}
)}
{agent.subAgents.length ? (
{agent.subAgents.map((subId) => (
{subId}
))}
) : null}
{agent.runtime === 'opencode' && agent.tokenUsage ?
: null}
)
}